<?php 
global $options;
foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
$dateformat = get_option('date_format');
$timeformat = get_option('time_format');
get_header(); ?>


  <div id="content" class="people">
    <div class="wrap">
    
      <div class="sep sepinside">&nbsp;</div>

      <div class="column column-narrow">
      
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar: Archive Pages') ) : ?>&nbsp;<?php endif; ?>
        
      </div><!-- end .column-narrow -->
      
      <div class="column column-double column-last">
      
		<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
 	  <?php /* If this is a category archive */ if (is_category()) { ?>
		<h1><?php single_cat_title(); ?></h1>
 	  <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
		<h1>Archive for: <?php single_tag_title(); ?></h1>
 	  <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
		<h1>Archive for <?php the_time('F jS, Y'); ?></h1>
 	  <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
		<h1>Archive for <?php the_time('F, Y'); ?></h1>
 	  <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
		<h1>Archive for <?php the_time('Y'); ?></h1>
	  <?php /* If this is an author archive */ } ?>

      <div class="posts affiliates_employees">
	
		<?php
			wp_reset_query();
		?>
		
		<?php
		
		// set up filtering by lab
		$tdoTag = 'meta_key=contact_details_employee_or_affiliate&meta_value=Employee&orderby=menu_order&order=ASC';
		if(isset($_GET['tdo_tag'])) {
			$tdoTag .= '&tag='.$_GET['tdo_tag'];
		}
		
		$newquery = new WP_Query($tdoTag);
			if ($newquery->have_posts()) {
				echo "<h2>Employees</h2>";
				while ($newquery->have_posts()) : $newquery->the_post();
					echo "<div class='post'>";
					
					$contactInfo = get_group('Contact Details'); // use the Custom Group name

						if (!is_null($contactInfo)) {
							echo "<div class='vcard'>";
					?>
								<h3>
									<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
										<?php 
											$contactInfo = get_group('Contact Details'); // use the Custom Group name
											if (!is_null($contactInfo)) {
												foreach($contactInfo as $info) {
													if ($info['contact_details_employee_or_affiliate'][1] == 'Employee' ) { echo $info['contact_details_salutation'][1]." "; }
												}
											}
											the_title();
										?>
									</a>
									<?php
										if ($info['contact_details_administrative_employee'][1] == 1 ) { echo "<em class='admin-staff'>Administrative Staff Member</em>"; }
									?>
								</h3>
								<?php
								unset($img);
								if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) {
									$attachedFile = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' );
									$img = $attachedFile[0]; 
								}
								else { 
									if ($proud_cf_use == 'Yes') {
										$img = get_post_meta($post->ID, $proud_cf_photo, true);
									} // if CF used
									else {
										if (!$img) {
											$img = catch_that_image($post->ID);
										}
									} // if CF not used
								}
								if ($img) {?>
									<div class="thumb"><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?h=80&amp;w=80&amp;zc=1&amp;src=<?php echo $img ?>" alt="<?php the_title(); ?>" class="bordered" /></a></div>
								<?php

								}
								?>
								
								<?php
								foreach($contactInfo as $info) {
									if (strlen($info['contact_details_professional_title'][1]) > 0 ) { 
										echo "<p class='title'>";
										
										echo "<em>".$info['contact_details_professional_title'][1]."</em>";
										echo "</p>";
									}
									$positionList = get('contact_details_position_title');
									if (!is_null($positionList) && count($positionList) >= 1) {
										echo "<div class='role'><p><strong>Position(s): </strong>";
										$arrayPos = count($positionList);
										foreach($positionList as $index => $value) {
											echo $value;
											if (($index+1) != $arrayPos) { echo ", "; }
										}
										echo "</p></div>";
									}
									if (strlen($info['contact_details_department_center'][1]) > 0 ) {
										echo "<div class='org'>";
										echo $info['contact_details_department_center'][1];
										if (strlen($info['contact_details_room_number'][1]) > 0 ) { echo ", ".$info['contact_details_room_number'][1]; }
										echo "</div>";
									}		
									if (strlen($info['contact_details_university_organization'][1]) > 0 ) { echo "<div class='org'>".$info['contact_details_university_organization'][1]."</div>"; }
									if (strlen($info['contact_details_email_address'][1]) > 0 ) { echo "<p class='email'><strong>Email: </strong><a class='email' href='mailto:".$info['contact_details_email_address'][1]."'>".$info['contact_details_email_address'][1]."</a></p>"; }
									if (strlen($info['contact_details_telephone_number'][1]) > 0 ) { echo "<div class='tel'><p><strong>Telephone: </strong><em>".$info['contact_details_telephone_number'][1]."</em></p></div>"; }
									if (strlen($info['contact_details_web_site'][1]) > 0 ) { echo "<p><strong>Web Site URL: </strong><a class='url' href='".$info['contact_details_web_site'][1]."'>".$info['contact_details_web_site'][1]."</a></p>"; }
								}
							echo "</div>";
						}
					?>
					<div class="clear">&nbsp;</div>
					</div> <!-- end .post -->
					<?php
				endwhile;
			}
		?>

		<?php
			wp_reset_query();
		?>
		
		<?php  
		
		// set up filtering by lab
		$tdoTag = 'meta_key=contact_details_employee_or_affiliate&meta_value=Affiliate&orderby=menu_order&order=ASC';
		if(isset($_GET['tdo_tag'])) {
			$tdoTag .= '&tag='.$_GET['tdo_tag'];
		}
		
		$newquery = new WP_Query($tdoTag);
			if ($newquery->have_posts()) {
				echo "<h2>Affiliates</h2>";
				while ($newquery->have_posts()) : $newquery->the_post();
					echo "<div class='post'>";
					
					$contactInfo = get_group('Contact Details'); // use the Custom Group name

						if (!is_null($contactInfo)) {
							echo "<div class='vcard'>";
					?>
								<h3>
									<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
										<?php 
											$contactInfo = get_group('Contact Details'); // use the Custom Group name
											if (!is_null($contactInfo)) {
												foreach($contactInfo as $info) {
													if ($info['contact_details_employee_or_affiliate'][1] == 'Affiliate' ) { echo $info['contact_details_salutation'][1]." "; }
												}
											}
											the_title(); 
										?>
									</a>
								</h3>
								<?php
								unset($img);
								if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) {
									$attachedFile = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' );
									$img = $attachedFile[0]; 
								}
								else { 
									if ($proud_cf_use == 'Yes') {
										$img = get_post_meta($post->ID, $proud_cf_photo, true);
									} // if CF used
									else {
										if (!$img) {
											$img = catch_that_image($post->ID);
										}
									} // if CF not used
								}
								if ($img) {?>
									<div class="thumb"><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?h=80&amp;w=120&amp;zc=1&amp;src=<?php echo $img ?>" alt="<?php the_title(); ?>" class="bordered" /></a></div>
								<?php

								}
								?>
								
								<?php
								foreach($contactInfo as $info) {
									if (strlen($info['contact_details_professional_title'][1]) > 0 ) { echo "<p class='title'><em>".$info['contact_details_professional_title'][1]."</em></p>"; }
									$positionList = get('contact_details_position_title');
									if (!is_null($positionList) && count($positionList) > 1) {
										echo "<div class='role'><p><strong>Position(s): </strong>";
										$arrayPos = count($positionList);
										foreach($positionList as $index => $value) {
											echo $value;
											if (($index+1) != $arrayPos) { echo ", "; }
										}
										echo "</p></div>";
									}
									if (strlen($info['contact_details_department_center'][1]) > 0 ) {
										echo "<div class='org'>";
										echo $info['contact_details_department_center'][1];
										if (strlen($info['contact_details_room_number'][1]) > 0 ) { echo ", ".$info['contact_details_room_number'][1]; }
										echo "</div>";
									}
									if (strlen($info['contact_details_university_organization'][1]) > 0 ) { echo "<div class='org'>".$info['contact_details_university_organization'][1]."</div>"; }
									if (strlen($info['contact_details_email_address'][1]) > 0 ) { echo "<p class='email'><strong>Email: </strong><a class='email' href='mailto:".$info['contact_details_email_address'][1]."'>".$info['contact_details_email_address'][1]."</a></p>"; }
									if (strlen($info['contact_details_telephone_number'][1]) > 0 ) { echo "<div class='tel'><p><strong>Telephone: </strong><em>".$info['contact_details_telephone_number'][1]."</em></p></div>"; }
									if (strlen($info['contact_details_web_site'][1]) > 0 ) { echo "<p><strong>Web Site URL: </strong><a class='url' href='".$info['contact_details_web_site'][1]."'>".$info['contact_details_web_site'][1]."</a></p>"; }
								}
							echo "</div>";
						}
					?>
					<div class="clear">&nbsp;</div>
					</div> <!-- end .post -->
					<?php
				endwhile;
			}
		?>


      <div class="navigation">
      <p><span class="older"><?php next_posts_link('&lt; older entries') ?></span>  <span class="latest"><?php previous_posts_link('newer entries &gt;') ?></span></p>
      </div>

      </div><!-- end .posts -->
      
      </div><!-- end .column-content -->
      
      <div class="clear">&nbsp;</div>

    </div><!-- end .wrap -->
  </div><!-- end #content -->

<?php get_footer(); ?>
